﻿// Self-Hosted WCF Service for Silverlight Template
// Created by Brice Wilson
// http://www.BriceWilson.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace SLServiceLibrary
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IGISService
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
        [OperationContract]
        List<MyTimeSeries> GetTimeSeriesList(List<string> names, string tag);

        [OperationContract]
        decimal GetLQ(string cityName, string countyName, DateTime Time, string industryTypeName, string industryType);
        //根据输入的参数求取区位商LQ；参数设置（产业名称、地区名称、时间）

        [OperationContract]
        Center GetCenter(string name, string type, List<Country> countryList);
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }

    [DataContract]
    public class Center
    {
        private string name;
        [DataMember]

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string type;
        [DataMember]
        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        private List<Point> pointList = new List<Point>();
        [DataMember]
        public List<Point> PointList
        {
            get { return pointList; }
            set { pointList = value; }
        }

        private List<DateTime> times = new List<DateTime>();
        [DataMember]
        public List<DateTime> Times
        {
            get { return times; }
            set { times = value; }
        }
    }
    [DataContract]
    public class MyTimeSeries
    {
        //int count;
        public int Count
        {
            get { return times.Count; }
        }
        List<DateTime> times = new List<DateTime>();
        [DataMember]
        public List<DateTime> Times
        {
            get { return times; }
            set { times = value; }
        }
        List<Decimal> values = new List<decimal>();
        [DataMember]
        public List<Decimal> Values
        {
            get { return values; }
            set { values = value; }
        }
        string titel = "TimeSeriesName";
        [DataMember]
        public string Titel
        {
            get { return titel; }
            set { titel = value; }
        }

    }



    [DataContract]
    public class Country
    {
        public Country clone() 
        {
            Country newCountry = new Country();

            newCountry.CountryName = this.CountryName;

            newCountry.Point = this.Point;

            newCountry.ParentCity = this.ParentCity.clone();

            return newCountry;
        }
        private List<Decimal> xDiList = new List<decimal>();
        //[DataMember]
        public List<Decimal> XDiList
        {
            get { return xDiList; }
            set { xDiList = value; }
        }
        private List<Decimal> yDiList = new List<decimal>();
        //[DataMember]
        public List<Decimal> YDiList
        {
            get { return yDiList; }
            set { yDiList = value; }
        }
        private string countryName;
        [DataMember]
        public string CountryName
        {
            get { return countryName; }
            set { countryName = value; }
        }

        private Point point;
        [DataMember]
        public Point Point
        {
            get { return point; }
            set { point = value; }
        }
        //
        private List<Decimal> valueList = new List<decimal>();
        //[DataMember]
        public List<Decimal> ValueList
        {
            get { return valueList; }
            set { valueList = value; }
        }

        private List<DateTime> timeList = new List<DateTime>();
        //[DataMember]
        public List<DateTime> TimeList
        {
            get { return timeList; }
            set { timeList = value; }
        }
        private List<decimal> diList = new List<decimal>();
        //[DataMember]
        public List<decimal> DiList
        {
            get { return diList; }
            set { diList = value; }
        }

        private City parentCity;
        //[DataMember]
        public City ParentCity
        {
            get { return parentCity; }
            set { parentCity = value; }
        }
        public Decimal GetValueByTime(DateTime time)
        {
            return this.valueList[this.timeList.IndexOf(time)];
        }
        public Decimal GetDiByTime(DateTime time) 
        {
            return this.DiList[this.timeList.IndexOf(time)];
        }
        public Decimal GetXDiByTime(DateTime time) { return this.XDiList[this.timeList.IndexOf(time)]; }

        public Decimal GetYDiByTime(DateTime time) { return this.YDiList[this.timeList.IndexOf(time)];}
        public void countDi()
        {
            //循环拿到年份
            foreach (var year in this.timeList)
            {
                this.DiList.Add(this.GetValueByTime(year) / this.ParentCity.GetValueByTime(year));
            }
            
        }
        public void counXYDi() 
        {
            foreach (var year in this.timeList)
            {
                this.XDiList.Add(this.GetDiByTime(year) * Convert.ToDecimal(this.Point.X));

                this.YDiList.Add(this.GetDiByTime(year) * Convert.ToDecimal(this.Point.Y));
            }
        }

    }
    [DataContract]
    public class Point
    {
        public Point clone() 
        {
            Point newPoint = new Point();

            newPoint.X = this.X;

            newPoint.Y = this.Y;

            return newPoint;
        }
        private string x;
        [DataMember]
        public string X
        {
            get { return x; }
            set { x = value; }
        }

        private string y;
        [DataMember]
        public string Y
        {
            get { return y; }
            set { y = value; }
        }
    }
}
